/*******************************************************************************
 * Copyright 2011 WaTho
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package de.wathoserver.android.dragoid.activity.util;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;
import de.wathoserver.android.dragoid.R;

/**
 * Aktivität zum Einstellungen der Benutzerdaten. Im Moment kann man genau einen
 * Permanent-Login-Link hinzufügen.
 * 
 * @author watho
 * 
 */
public class AccountActivity extends PreferenceActivity {

	private static final int DIALOG_NO_INIT = 100;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.account);
		ListPreference lp = (ListPreference) findPreference("account_selected_account");
		lp.setEntries(new String[] { "t" });
		lp.setEntryValues(new String[] { "test" });
		lp.setEnabled(true);
		if (getIntent().getBooleanExtra("automatic", false)) {
			showDialog(DIALOG_NO_INIT);
		}
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		Dialog dialog = null;
		switch (id) {
		case DIALOG_NO_INIT:
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage(
					"Es fehlen die Accounteinstellungen.\nBitte kopiere den Permanent-Login-Link, den du über die Dragosien-Einstellungen anfordern kannst, in das Textfeld.")
					.setCancelable(false)
					.setNeutralButton("OK",
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									removeDialog(DIALOG_NO_INIT);
								}
							});
			dialog = builder.create();
			return dialog;

		default:
			return super.onCreateDialog(id);
		}
	}
}
